from django.db import models

# Create your models here.
from django.contrib.auth.models import User


class Lable(models.Model):
    name = models.CharField(max_length=20,unique=True,verbose_name='题目标签')#unique是唯一约束
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    class Meta:
        db_table = 'lable'
        verbose_name = '标签名称'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


class Topic(models.Model):
    TYPE_CHOICES = (
        (0, '单选题'),
        (1, '多选题'),
        (2, '判断题'),
        (3, '填空题'),
        (4, '问答题'),
    )
    subject = models.TextField(verbose_name='题干')
    type = models.IntegerField(verbose_name='类型',choices=TYPE_CHOICES)
    score = models.FloatField(verbose_name='分值',default=1.0,null=True,blank=True)#blank是可以为空，null是让空字段为Null
    description = models.TextField(verbose_name='题目描述',null=True,blank=True)
    answer = models.TextField(verbose_name='答案',null=True,blank=True)

    lable = models.ForeignKey(Lable,on_delete=models.CASCADE)
    user = models.ForeignKey(User,on_delete=models.CASCADE)

    class Meta:
        db_table = 'topic'
        verbose_name = '题目'
        verbose_name_plural = verbose_name

